#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

typedef int64_t num_t;
#define num_sch SCNd64
#define num_pph PRId64

typedef struct {
    num_t number;
    int count;
} pair_t;

pair_t pairs[1000];
int pair_count = 0;

void clean_pairs() {
    pair_count = 0;
}

void print_pairs() {
    printf("count: %d\n", pair_count);
    for (int i = 0; i < pair_count; i++) {
        printf("%" num_pph "^%d\n", pairs[i].number, pairs[i].count);
    }
}

void insert_pair(pair_t pair) {
    pairs[pair_count] = pair;
    pair_count++;
}

#define insert_number(num, cnt) { \
    pair_t pair;                  \
    pair.number = (num);          \
    pair.count = (cnt);           \
    insert_pair(pair);            \
}

void get_pairs(num_t number) {
    pair_count = 0;
    if (number < 2) {
        insert_number(number, 1);
        return;
    }
    num_t now = 2;
    int count = 0;
    while (number != 1 || count != 0) {
        if (number % now != 0 || (number == 1 && count != 0)) {
            if (count != 0) {
                insert_number(now, count);
            } else {
                if (now * now >= number) {
                    insert_number(number, 1);
                    break;
                }
            }
            count = 0;
            now++;
        } else {
            number /= now;
            count++;
        }
    }
}

// 递归 计算每一个count的组合数的所有组合的相乘之和
int go(int res, int index) {
    int result = res * pairs[index].count;
    // 当前项后面的
    for (int i = index + 1; i < pair_count; i++) {
        result += go(res * pairs[index].count, i);
    }
    //printf("res: %d, index: %d\n", result, index);
    return result;
}

int logic(num_t number) {
    clean_pairs();
    get_pairs(number);
    //print_pairs();
    int result = 1; // 1
    for (int i = 0; i < pair_count; i++) {
        //printf("index: %d, res: %d\n", i, result);
        result += go(1, i);
    }
    return result;
}

int main(void) {
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++) {
        num_t a, b;
        scanf("%" num_sch "%" num_sch, &a, &b);
        printf("%d\n", logic(a + b));
    }
    return 0;
}
